package cn.huiyunche.admin.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.huiyunche.base.service.interfaces.BAreaService;
import cn.huiyunche.base.service.model.BArea;
import cn.huiyunche.base.service.vo.BAreaCityRatingVo;
import cn.huiyunche.base.service.vo.PageVo;
import cn.huiyunche.base.service.vo.Result;

@Controller
@RequestMapping("/area")
public class AreaController {

	@Autowired
	private BAreaService areaService = null;

	@ResponseBody
	@RequestMapping(value = "/loadarea", method = RequestMethod.GET)
	public Result<List<BArea>> selectAreaByPinyin() {
		Result<List<BArea>> result = new Result<List<BArea>>(true, null, "数据加载成功");
		result.setData(this.getAreaService().selectAreaByPinyin());
		return result;
	}

	@ResponseBody
	@RequestMapping(value = "/loadprovince", method = RequestMethod.GET)
	public Result<List<BArea>> loadprovince() throws Exception {
		Result<List<BArea>> result = new Result<List<BArea>>(true, null, "省数据加载成功");
		result.setData(this.getAreaService().selectProvinceList());
		return result;
	}

	@ResponseBody
	@RequestMapping(value = "/loadcity", method = RequestMethod.GET)
	public Result<List<BArea>> loadcity() throws Exception {
		Result<List<BArea>> result = new Result<List<BArea>>(true, null, "市数据加载成功");
		result.setData(this.getAreaService().selectCity());
		return result;
	}

	@ResponseBody
	@RequestMapping(value = "/loadcity/{code}", method = RequestMethod.GET)
	public Result<List<BArea>> loadCityByCode(@PathVariable String code) throws Exception {
		Result<List<BArea>> result = new Result<List<BArea>>(true, null, "数据加载成功");
		result.setData(this.getAreaService().selectCityByProvinceCode(code));
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value = "/loadcounty/{code}", method = RequestMethod.GET)
	public Result<List<BArea>> loadCountyByCode(@PathVariable String code) throws Exception {
		Result<List<BArea>> result = new Result<List<BArea>>(true, null, "数据加载成功");
		result.setData(this.getAreaService().selectCountyByCityCode(code));
		return result;
	}
	
	/**
	 * 查询省市 城市级别
	 * @param bAreaCityRatingVo
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/cityratinglist", method = RequestMethod.POST)
	public Result<Map<String, Object>> selectCityRatingList(PageVo page, BAreaCityRatingVo bAreaCityRatingVo) throws Exception {
		Result<Map<String, Object>> result = new Result<Map<String, Object>>(true, null, "数据加载成功");
		result.setData(this.getAreaService().selectCityRatingList(page, bAreaCityRatingVo));
		return result;
	}
	
	/**
	 * 更新省市 城市级别
	 * @param bAreaCityRatingVo
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/updatecityrating", method = RequestMethod.POST)
	public Result<String> updateCityRating(BAreaCityRatingVo bAreaCityRatingVo) throws Exception {
		return this.getAreaService().updateCityRating(bAreaCityRatingVo);
	}

	private BAreaService getAreaService() {
		return this.areaService;
	}
}
